package com.book.constant;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.apache.log4j.Logger;

/**
 * 常量配置类，从指定文件读取常量
 * 
 * @author linsy
 * @since 2007-4-25
 */
public class ConfigurableContants {
	private static final Logger logger = Logger.getLogger(ConfigurableContants.class);
	private static final Properties p = new Properties();

	public static void init(String propertyFileName) {
		InputStream in = null;
		try {
			in = ConfigurableContants.class.getResourceAsStream(propertyFileName);
			if (in != null) {
				p.load(in);
			}
		} catch (IOException e) {
			logger.error("load " + propertyFileName + " into Contants error");
		} finally {
			if (in != null) {
				try {
					in.close();
				} catch (IOException e) {
				}
			}
		}
	}

	public static String getProperty(String key, String defaultValue) {
		return p.getProperty(key, defaultValue);
	}

	public static String getProperty(String key) {
		return p.getProperty(key);
	}

	public static Object setProperty(String key, String value) {
		return p.setProperty(key, value);
	}
}
